package com.example.android_sqlite;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.List;

public class ShowInfoAdapter extends BaseAdapter {

    private List<String> list = new ArrayList<>();

    public void refresh(List<String> list) {
        this.list.clear();
        this.list.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if( convertView == null) convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list_view, parent, false);
        TextView mItemListName = convertView.findViewById(R.id.item_list_name);
        mItemListName.setText(list.get(position));
        return convertView;
    }
}
